#include "PlayState.h"
#include "EntityManager.h"
#include "Player.h"
#include "Ladder.h"
#include "Controls.h"
#include "StateManager.h"
#include "MainMenuState.h"
#include "PauseState.h"
#include "Level.h"
#include "Rolling.h"
#include "SpecialEffectManager.h"
#include "HUDManager.h"

PlayState::PlayState()
{ 
	_id = "PlayState";
	_hudManager = nullptr;
}


PlayState::~PlayState(void) {}

void PlayState::update()
{
	_level->update();

	if (_inputManager->isKeyPressed(sf::Keyboard::P))
	{
		_stateManager->setActiveState("PauseState", true);
		_stateManager->skipUpdateCycle("PauseState", 1);
		_update = false;
		_controlState->setUpdateState(false);
	}

	_entityManager->update();
	if (SpecialEffectManager::getSingletonPtr()->checkForEffects())
		SpecialEffectManager::getSingletonPtr()->update();
}

void PlayState::input()
{

}

void PlayState::draw(RenderManager* renderManager)
{
	renderManager->setView(VIEW_STANDARD);
	_level->draw(renderManager);
	_entityManager->draw(renderManager);
	if (SpecialEffectManager::getSingletonPtr()->checkForEffects())
		SpecialEffectManager::getSingletonPtr()->draw(renderManager);
	renderManager->setView(VIEW_FRONT);
	_hudManager->draw(renderManager);
}

void PlayState::initialize()
{
	_stateManager->stateTransition(-100);
}

void PlayState::shutdown()
{
	int p = 0;
}

void PlayState::loadContent()
{
	_hudManager = new HUDManager;
	_level = new Level("level01.xml");
	_level->loadLevel();
	_entityManager = std::shared_ptr<EntityManager>(new EntityManager(_level));
	_entityManager->addEntity(new Ladder(sf::Vector2f(96.0f, 96.0f), "LAD_GRN_TOP", "LAD_GRN_MID", 4));
	_entityManager->addEntity(new Player(_controlState, "ZERO", _entityManager.get(), _hudManager));
	_entityManager->addEntity(new Rolling());
}

void PlayState::unloadContent()
{
	_level->unloadLevel();
	delete _level;
	_level = nullptr;
	delete _hudManager;
	_hudManager = nullptr;
}
